package com.qs.eggs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.qs.eggs.Constants;
import com.qs.eggs.R;
import com.qs.eggs.account.LoginActivity;
import com.qs.eggs.api.HttpApi;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Response;


public class PicAdapter extends BaseAdapter {
    List<Map<String, Object>> giflist=new ArrayList<>();
    private Context context;


    public PicAdapter(Context context, List<Map<String, Object>> giflist) {
        super();
        this.context = context;
        this.giflist = giflist;
    }
    @Override
    public int getCount() {
        return giflist.size();
    }


    @Override
    public Object getItem(int position) {
        return giflist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
       ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.orderpic, null);
            holder.content= (TextView) convertView.findViewById(R.id.tv_content);
            holder.price= (TextView) convertView.findViewById(R.id.tv_price);
            holder.count = (TextView) convertView.findViewById(R.id.tv_count);
            holder.pic = (SimpleDraweeView) convertView.findViewById(R.id.propic);
            convertView.setTag(holder);
        } else {
            // 取出holder
            holder = (ViewHolder) convertView.getTag();
        }
        Picasso.with(context).load(Constants.URL_BASE+"productimages"+"/"+giflist.get(position).get("autoname"))
                .into(holder.pic);
        holder.content.setText(giflist.get(position).get("proname").toString());
        holder.price.setText("¥"+giflist.get(position).get("price")+"");
        holder.count.setText("x"+giflist.get(position).get("count")+"");
        return convertView;
    }

    public class ViewHolder {

        TextView price,content,count;
        SimpleDraweeView pic;
    }

}
